using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Shapes;
using Mvvm;
using Point = LayoutPlanning.Model.Point;

namespace LayoutPlanning.Converters
{
    public class RectConvertor : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (ViewModelBase.IsInDesignMode)
                return null;
            if (values.Count() > 2)
            {
                var l = (Point) values[0];
                var sx = (double) values[1];
                var sy = (double) values[2];


                return new Rect(new System.Windows.Point(l.X - sx/2, l.Y - sy/2),
                    new Size(sx, sy));
            }
            else
            {
                return new Rect(new Size((double) values[0], (double) values[1]));
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
            System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}